package homework7;

interface Flyable {
    void fly();
}


class Bird implements Flyable {
    private int height;
    private int speed;


    public Bird(int height, int speed) {
        this.height = height;
        this.speed = speed;
    }


    @Override
    public void fly() {
        System.out.println("The bird is flying at a height of " + height + " meters with a speed of " + speed + " m/s.");
    }
}


class Plane implements Flyable {
    private int passengerCapacity;
    private int range;


    public Plane(int passengerCapacity, int range) {
        this.passengerCapacity = passengerCapacity;
        this.range = range;
    }


    @Override
    public void fly() {
        System.out.println("The plane is flying with " + passengerCapacity + " passengers and has a range of " + range + " kilometers.");
    }
}


class Drone implements Flyable {
    private int batteryLife;
    private boolean hasCamera;


    public Drone(int batteryLife, boolean hasCamera) {
        this.batteryLife = batteryLife;
        this.hasCamera = hasCamera;
    }


    @Override
    public void fly() {
        System.out.println("The drone is flying with a battery life of " + batteryLife + " minutes.");
        if (hasCamera) {
            System.out.println("The drone is using its camera to take photos or videos.");
        }
    }
}


class Superman implements Flyable {
    private boolean transformed;


    public Superman() {
        this.transformed = false;
    }


    @Override
    public void fly() {
        System.out.println("Superman is flying.");
    }


    public void transform() {
        transformed =!transformed;
        if (transformed) {
            System.out.println("Superman has transformed.");
        } else {
            System.out.println("Superman has transformed back.");
        }
    }
}


public class Main {
    public static void main(String[] args) {
        // 创建 Bird 对象并测试
        Bird bird = new Bird(100, 20);
        bird.fly();


        // 创建 Plane 对象并测试
        Plane plane = new Plane(200, 5000);
        plane.fly();


        // 创建 Drone 对象并测试
        Drone drone = new Drone(30, true);
        drone.fly();


        // 创建 Superman 对象并测试
        Superman superman = new Superman();
        superman.fly();
        superman.transform();
        superman.transform();


        // 更复杂的测试场景，可以创建数组或集合存储 Flyable 对象，并使用循环调用 fly 方法
        Flyable[] flyables = new Flyable[4];
        flyables[0] = new Bird(150, 25);
        flyables[1] = new Plane(300, 6000);
        flyables[2] = new Drone(40, false);
        flyables[3] = new Superman();


        for (Flyable flyable : flyables) {
            flyable.fly();
        }
    }
}